<template>
  <div style="height: 100%;">
    <x-header :left-options="{preventGoBack:preventGoBack,backText: ''}" @on-click-back="todangerlist">隐患上报</x-header>
    <div class="hidanger-title">隐患条目:<label class="hidanger-chosetask" @click="hidlist"><img src="../../assets/img/hdangerlist.png" style="width:28px"></label></div>
    <div class="hidanger-title"><span v-if="(hazardclause != null)" style="width:33px;display:inline-block"></span><span style="padding-left:0px;">{{hazardclause}}</span></div>
    <hr class="hidanger-hr"/>
    <div><pointpathlist v-on:selectvalue="selectvalue"><label slot="pointNamechosetask" v-if="(pointName == null)">选择工点</label><label slot="pointName">{{pointName}}</label></pointpathlist></div>
    <div class="hidanger-lab" @click="chosetask">隐患排查任务<label class="hidanger-chosetask" v-if="(checkmisscontent == null)" style="padding-right:12px">选择所属排查任务<label class="chosetask-lab"></label></label><label class="hidanger-chosetask hidanger-chosetaskfontshow" style="color:#343434;padding-right:12px">{{checkmisscontent}}<label class="chosetask-lab" v-if="(checkmisscontent != null)"></label></label></div>
    <div class="hidanger-lab">排查时间<label class="hidanger-chosetask" style="color:#343434;">{{startime}}</label></div>
    <hr class="hidanger-hr"/>
    <!--div-- class="hidanger-lab">
    <group>
      <datetime class="datetime-lab"  :value.sync="value5" placeholder="请选择日期" :min-year=2019 :max-year=2100 format="YYYY-MM-DD HH:mm" @on-change="change" title="排查时间" year-row="{value}年" month-row="{value}月" day-row="{value}日" hour-row="{value}点" minute-row="{value}分" confirm-text="完成" cancel-text="取消" @on-hide="cellvacolor(confirm)"></datetime>
    </group>
    </div-->
    <div class="hidanger-lab">隐患等级<label class="hidanger-chosetask" style="color:#343434;">{{hidangername}}</label></div>
    <div class="hidanger-lab">隐患类型<label class="hidanger-chosetask" style="color:#343434;">{{hidangertype}}</label></div>
    <div class="hidanger-lab">隐患大类<label class="hidanger-chosetask" style="color:#343434;">{{hidangercategory}}</label></div>
    <div class="hidanger-lab">隐患分项<label class="hidanger-chosetask" style="color:#343434;">{{hidangerkind}}</label></div>
    <hr class="hidanger-hr"/>
    <!--div class="hidanger-lab">隐患描述</div>
    <div class="hidanger-lab"><textarea class="hidanger-textarea" placeholder="输入隐患描述"></textarea></div>
    <hr class="hidanger-hr"/-->
    <div class="hidanger-lab">隐患现场照片</div>
    <div class="hidanger-lab"><picture-upload></picture-upload><picture-upload></picture-upload><picture-upload></picture-upload><picture-upload></picture-upload><picture-upload></picture-upload></div>
    <hr class="hidanger-hr"/>
    <div class="content-container">
    <group label-width="100px" :gutter="0">
      <person-tree  title="隐患负责人" ref="executeLeader"></person-tree>
    </group>
    </div>
    <hr class="hidanger-hr"/>
    <div class="hidanger-lab">上报人<label class="hidanger-chosetask" style="color:#343434;">陈敏</label></div>
    <div class="hidanger-lab">联系电话<label class="hidanger-chosetask" style="color:#343434;">13847560394</label></div>
    <div class="hidanger-lab">上报部门<label class="hidanger-chosetask" style="color:#343434;">华东勘测设计研究院有限公司</label></div>
    <div class="hidanger-lab">上报时间<label class="hidanger-chosetask" style="color:#343434;">{{timeFormate}}</label></div>
    <div class="hidanger-lab"><button class="hidanger-button" @click="reportDanger">上报</button></div>
    <router-view></router-view>
    <Toast :value="toastValue" is-show-mask="true" text="上报成功" @on-hide="reportSuccess"></Toast>
    <Toast :value="toastValueErr" is-show-mask="true" :text="err" @on-hide="reportErr" type="cancel" width="200px"></Toast>
  </div>
</template>

<script>
import { Confirm } from 'vux'
import { Alert } from 'vux'
import pointpathlist from '../hidangereport/pointpathlist.vue';
import { Toast } from 'vux'

export default {
  name: "reportdanger",
  components: {
    Confirm,
    Alert,
    pointpathlist,
    Toast
  },
  mounted () { },
  data () {
    return {
      list: [],
      page: 1,
      keyword: '',
      createPop: false,//弹出层是否创建
      loading: false,//下拉刷新时禁止无限加载
      nowTime:'',
      hidangername:this.$route.query.hidangername,
      hazardclause:this.$route.query.hazardclause,
      hidangertype:this.$route.query.hidangertype,
      hidangercategory:this.$route.query.hidangercategory,
      hidangerkind:this.$route.query.hidangerkind,
      checkmisscontent:this.$route.query.checkmisscontent,
      startime:this.$route.query.startime,
      hazardclauseid:this.$route.query.hazardclauseid,
      pathid:this.$route.query.pathid,
      pointName:this.$route.query.pointName,
      toastValue:false,
      toastValueErr:false,
      err:""
    }
  },
  methods: {
      selectvalue(data){
          this.pointName = data[0]
          this.pathid = data[1];
      },
      sPageToken(){
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
              let r = Math.random() * 16 | 0,
              v = c == 'x' ? r : (r & 0x3 | 0x8);
              return v.toString(16);
          });
      },
      reportDanger(){
          var obj = {};
          obj["process"] = "流程";
          obj["method"] = "formService.saveFormData";
          obj["useType"] = "add";
          obj["pageToken"] = this.sPageToken();
          //requestEventData部分
          obj["eventType"] = "formSubmitEvent";
          obj["bizObjId"] = "HAZARD_RESOLVING";
          obj["formId"] = "HazardResolving_add";
          obj["buttonId"] = "HandleCommand_1";
          //flowParam部分
          obj["defKey"] = "HAZARD_RESOLVING";
          obj["nodeId"] = "UserTask_1";
          obj["userCommandType"] = "startandsubmit";
          obj["userCommandId"] = "HandleCommand_1";
          obj["taskComment"] = "";

          obj["pks"] = "GUID";
          var rowData = [];
          var GUID = "";
          var STATE = "";
          var POINTPATHID = this.pathid;
          var RELATEDCHECK = this.checkmisscontent;
          var RELATEDCHECKTIME = this.startime;
          var HAZARDCLAUSE = this.hazardclause;
          var HAZARDGUID = this.hazardclauseid;
          var HAZARDLEVEL = this.hidangername;
          var HAZARDTYPE = this.hidangertype;
          var HAZARDCATEGORY = this.hidangercategory;
          var HAZARDKIND = this.hidangerkind;
          var ATT_HAZARD = "b9f330cd-b791-4e8c-4328-ade2b888becd";
          var AUDITUSERFULLNAME_XY = "陈敏";
          var AUDITUSERNAME_XY = "chen_m2";
          var NAME_REPORTER = "陈敏";
          var USERNAME_REPORTER = "chen_m2";
          var PHONENUM_REPORTER = "13847560394";
          var DEPTNAME_REPORTER = "华东勘测设计研究院有限公司";
          var DEPTPATHID_REPORTER = ".0.2691.2692.";
          var REPORTTIME = this.timeFormate;
          var HASSCHEME = "1";
          this.err = "";
          if(RELATEDCHECK == null){
            this.err += "【隐患排查任务】不能为空<br/>";
          }
          if(HAZARDCLAUSE == null){
            this.err += "【隐患条目】不能为空<br/>";
          }
          if(AUDITUSERFULLNAME_XY == null){
            this.err += "【隐患负责人】不能为空<br/>";
          }
          if(this.err != ""){
            this.toastValueErr = true;
            return false;
          }

          rowData[0] = this.setRowData("GUID", GUID, null, true, "String");
          rowData[1] = this.setRowData("STATE", STATE, null, false, "String");
          rowData[2] = this.setRowData("POINTPATHID", POINTPATHID, null, false, "String");
          rowData[3] = this.setRowData("RELATEDCHECK", RELATEDCHECK, null, false, "String");
          rowData[4] = this.setRowData("RELATEDCHECKTIME", RELATEDCHECKTIME, null, false, "TimeStamp");
          rowData[5] = this.setRowData("HAZARDCLAUSE", HAZARDCLAUSE, null, false, "String");
          rowData[6] = this.setRowData("HAZARDGUID", HAZARDGUID, null, false, "String");
          rowData[7] = this.setRowData("HAZARDLEVEL", HAZARDLEVEL, null, false, "String");
          rowData[8] = this.setRowData("HAZARDTYPE", HAZARDTYPE, null, false, "String");
          rowData[9] = this.setRowData("HAZARDCATEGORY", HAZARDCATEGORY, null, false, "String");
          rowData[10] = this.setRowData("HAZARDKIND", HAZARDKIND, null, false, "String");
          rowData[11] = this.setRowData("ATT_HAZARD", ATT_HAZARD, null, false, "Store.ecidiDoc");
          rowData[12] = this.setRowData("AUDITUSERFULLNAME_XY", AUDITUSERFULLNAME_XY, null, false, "String");
          rowData[13] = this.setRowData("AUDITUSERNAME_XY", AUDITUSERNAME_XY, null, false, "String");
          rowData[14] = this.setRowData("NAME_REPORTER", NAME_REPORTER, null, false, "String");
          rowData[15] = this.setRowData("USERNAME_REPORTER", USERNAME_REPORTER, null, false, "String");
          rowData[16] = this.setRowData("PHONENUM_REPORTER", PHONENUM_REPORTER, null, false, "String");
          rowData[17] = this.setRowData("DEPTNAME_REPORTER", DEPTNAME_REPORTER, null, false, "String");
          rowData[18] = this.setRowData("DEPTPATHID_REPORTER", DEPTPATHID_REPORTER, null, false, "String");
          rowData[19] = this.setRowData("REPORTTIME", REPORTTIME, null, false, "String");
          rowData[20] = this.setRowData("HASSCHEME", HASSCHEME, null, false, "String");

          obj["rowData"] = JSON.stringify(rowData);
          obj["children"] = "";
          var sText = this.sendText(obj);

          this.$ajax({
                    method: 'post',
                    url: this.COMMON_URL +'?_viewId=HarzadResolving_List&_menuId=fb804d3d-3783-4a35-93d2-9645736541b6&objName=HAZARD_RESOLVING&name=%E5%87%A4%E6%9E%97%E8%B7%AF%E7%AB%99&GUID=393d0520fe315886ef2a87fd73c9b960&Pathid=.1.2.125.136.&treeNodeId=136&PARENTNAME=%E6%96%BD%E5%B7%A5%E6%A0%87SXGD1-TJSG-01%E6%A0%87&PARENTID=125&_useType=add&_defKey=HAZARD_RESOLVING&_t=184259&_winid=w1639',
                    data: {
                      FixJSON: sText
                    }
                }).then((res) => {
                    console.log(res);
                    this.toastValue=true;
                }).catch((err)=>{
                     console.log(err);
                    alert(err);
                });
      },
      setRowData(DataTarget, Value, OriginalValue, PK, DataType){
        var map = {};
        map["DataTarget"] = DataTarget;
        map["Value"] = Value;
        map["OriginalValue"] = OriginalValue;
        map["PK"] = PK;
        map["DataType"] = DataType;
        return map;
      },
      sendText(obj) {
        var vText = '{' + '"_method":"' + obj.method + '",  ' 
              + '"requestEventData": {' 
              + '		"eventType": "' + obj.eventType + '", ' 
              + '		"formType": 1,  ' 
              + '		"bizObjId": "'+ obj.bizObjId + '",  ' 
              + '		"formId": "' + obj.formId + '",  ' 
              + '		"buttonId": "' + obj.buttonId + '"  ' 
              + '},' ;
        
        if(obj.process=="流程"){
          vText += '"flowParam": {'    //带流程的加此字段，否则不加flowParam信息
            +'"defKey": "'+obj.defKey+'",'
            +'"nodeId": "'+obj.nodeId+'",'
            +'"userCommandType": "'+obj.userCommandType+'",'  //页面上操作按钮类型比如提交、同意、拒绝等
            +'"userCommandId": "'+obj.userCommandId+'",'
            +'"isAdmin": "false",'
            +'"extParam": {}},';
        }
        vText +=  '"_OBJ_NAME_":"' + obj.bizObjId + '",' 
              + '"_FORM_ID_": "' + obj.formId + '",  ' 
              + '"useType": "' + obj.useType+ '",  ' 
              + '"pageToken": "' + obj.pageToken+ '",  ' 
              + '"formData": {' 
              + '    "objName": "' + obj.bizObjId + '",  ' 
              + '    "pks": ["'+obj.pks+'"],' 
              + '"data":[{"rowData":' + obj.rowData + ',"children": ['+obj.children+']}]},'
              + '"_ATTACHMENT_DELETE_IDS_":"",'
            + '"formInfo": {}' 
          + '}';
        return vText;
      },
      todangerlist(){
         this.$router.push('/hidangereport');
      },
      hidlist(){
         this.$router.push({
            path:'/hidangereport/reportdanger/dangerentrylist',
            query:{
              checkmisscontent:this.checkmisscontent,
              startime:this.startime,
              pathid:this.pathid,
              pointName:this.pointName
            }
        })
      },
      chosetask(){
        this.$router.push({
            path:'/hidangereport/reportdanger/dangertask',
            query:{
              hidangername:this.hidangername,
              hazardclause:this.hazardclause,
              hidangertype:this.hidangertype,
              hidangercategory:this.hidangercategory,
              hidangerkind:this.hidangerkind,
              hazardclauseid:this.hazardclauseid,
              pathid:this.pathid,
              pointName:this.pointName
            }
        })
      },
      reportSuccess(){
        this.todangerlist();
      },
      reportErr(){
        this.toastValueErr = false;
      }
  },
  computed: {
      preventGoBack(){
        return true;
      },
      timeFormate(nowTime){
          var date = new Date;
          let year = date.getFullYear();
          let month = date.getMonth() + 1;
          let day = date.getDate();
          let hour = date.getHours();
          let minute = date.getMinutes();
          var nowTime = year + "-" + month + "-" + day + " " + hour + ":" + minute;
          return nowTime;
      },
      user() {
          return this.$store.state.user
        }
    // userInfo () {
    //   return this.$store.state.user
    // },
    // mainPop () {
    //   return this.$store.state.mainPop
    // }
  },
  watch: {
    // '$route' () {
    //   if (this.$route.query.refresh) {
    //     this.$router.push('/task')
    //     // this.changeType(this.currentTab)
    //   }
    //   this.$store.commit('updateLoadingStatus', false);
    // }
  }
}
</script>

<style scoped>
   *{
       background-color: #fff;
   }
  .card {
    background: #fff;
    margin: 10px 16px;
    padding: 20px;
    border-radius: 4px;
    overflow: hidden;
  }

  .card-title {
    font-size: 18px;
  }
  .warning {
    color: red;
    padding: 0 5px;
    background-color: pink;
    text-align: center;
    width: 140px;
    line-height: 30px;
    font-size: 14px;
  }

  .gray-label {
    color: gray;
  }

  .hidanger-title{
    margin-top: 13px;
    margin-bottom: 13px;
    margin-left: 40px;
    margin-right: 40px;
    font-size: 16px;
  }

  .hidanger-hr{
    margin-left: 40px;
    margin-right: 40px;
    background-color: #F2F4F6;
    height: 1pt;
    border: none;
  }
  .hidanger-lab{
    margin-top: 13px;
    margin-bottom: 13px;
    margin-left: 40px;
    margin-right: 40px;
    color: #9F9F9F;
    font-size: 13px;
  }
  .hidanger-textarea{
    width: 100%;
    resize: none;
    height: 105pt;
    padding: 10pt 14pt;
    box-sizing: border-box;
    border: 1pt solid #9F9F9F;
    border-radius: 2pt;
    font-size: 13px;
  }
  .hidanger-textarea::-webkit-input-placeholder{
      color: #9F9F9F;
      font-size: 13px;
  }
  .hidanger-button{
      width: 100%;
      height: 40pt;
      background-color: #4852D0;
      border-radius: 2pt;
      border: 1pt solid #4852D0;
      margin-top: 20pt;
      color: #FEFEFE;
      font-size: 13pxt;
  }
  .hidanger-chosetask{
      text-align: right;
      float: right;
  }
  .datetime-lab{
    margin:0;
    padding-left: 0px;
    padding-right: 0px;
    color: #9F9F9F;
    font-size: 13px;
  }
  .vux-datetime .weui-cell .datetime-lab .weui-cell_access{  
    padding-left: 0px;
    padding-right: 0px;
  }
  .content-container{
      height:40px;
      overflow-y:auto;
      background-color:white;
      padding-top:0px;
      padding-bottom:0px;
  }
  .chosetask-lab:after{
    content: " ";
    height: 6px;
    width: 6px;
    border-width: 2px 2px 0 0;
    border-color: #C8C8CD;
    border-style: solid;
    transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
    position: absolute;
    margin-top: 6px;
    margin-left: 5px;
    clear: both;
    float: right;
  }
  .hidanger-chosetaskfontshow{
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 65%
  }
</style>